package cn.edu.hstc.wm.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import cn.edu.hstc.wm.AppApplication;
import cn.edu.hstc.wm.Constants;
import cn.edu.hstc.wm.utils.LogUtil;

/**
 * @ClassName: NetCheckReceiver
 * @Description: 网络状况检查监听器
 * 
 * @ModificationHistory
 */
public class NetCheckReceiver extends BroadcastReceiver {

	// android 中网络变化时所发的Intent的名字
	public static final String NET_CHANGE_ACTION = "android.net.conn.CONNECTIVITY_CHANGE";

	@Override
	public void onReceive(Context context, Intent intent) {

		if (intent.getAction().equals(NET_CHANGE_ACTION)) {

			LogUtil.i("NetCheckReceiver", "onReceive");

			// Intent中ConnectivityManager.EXTRA_NO_CONNECTIVITY这个关键字表示着当前是否连接上了网络
			// true 代表网络断开 false 代表网络没有断开
			if (intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false)) {
				AppApplication.netWorkStatus = Constants.NET_TYPE_DISCONN;
			} else {
				AppApplication.netWorkStatus = Constants.NET_TYPE_CONN;
			}
		}
	}
}
